package FanShe1;

public class TestCar2 {
    public static void main(String[] args) throws ClassNotFoundException {
        String classAllPath = "FanShe1.Car";
        //1.获取反射类对象cls
        Class<?> cls = Class.forName(classAllPath);
        System.out.println("cls = " + cls);
        //2.
        Class<Car> cls1 = Car.class;
        System.out.println("cls1 = " + cls1);
        //3.
        Car car = new Car();
        Class<? extends Car> cls3 = car.getClass();
        System.out.println("cls3 = " + cls3);
        //4.通过类加载器获取Class反射对象
        //1. 先得到类加载器
        ClassLoader classLoader = car.getClass().getClassLoader();
        //2. 通过类加载器得到Class对象
        Class<?> cls4 = classLoader.loadClass(classAllPath);
        System.out.println("cls4 = " + cls4);

        System.out.println("cls.hashCode() = " + cls.hashCode());
        System.out.println("cls1.hashCode() = " + cls1.hashCode());
        System.out.println("cls3.hashCode() = " + cls3.hashCode());
        System.out.println("cls4.hashCode() = " + cls4.hashCode());
        //基本类型怎么生成反射类对象  int  double 传参
        Class<Integer> integerClass = int.class;
        Class<Character> characterClass = char.class;
        Class<Boolean> booleanClass = boolean.class;
        System.out.println("integerClass = " + integerClass);
        System.out.println("characterClass = " + characterClass);

        //2. 基本类型对应包装类通过反射获取
        Class<Integer> type1 = Integer.TYPE;
        System.out.println("type1 = " + type1);
        Class<Character> type2 = Character.TYPE;
        System.out.println("type2 = " + type2);
    }

}

